Skip to content

Dev#113

Merged
kaste merged 10 commits intomasterfrom
dev
Mar 4, 2026
Merged

Dev#113
kaste merged 10 commits intomasterfrom
dev

Conversation

@kaste
Copy link
Copy Markdown
Owner

@kaste kaste commented Mar 4, 2026

Some fixes but also rollback the "specifiticity" feature. Last-one-wins is easy enough to explain, and esp. has no surprises when you configure first in setUp and then want to to tune that in a test file. Here clearly the later config should win.

Treat __aenter__, __aexit__, and __anext__ as awaitable protocol
methods for unspecced mock() objects when configured via
when(...).thenReturn/thenRaise/thenAnswer flows.

Centralize awaitable detection in Mock.method_expects_awaitable().
Reuse it for method replacement coroutine marking, and update
StubbedInvocation to use the shared logic.

Add focused regression tests in tests/async_protocol_methods_test.py,
including functional async with and async for scenarios, plus
awaitable checks for __aenter__/__aexit__ and __anext__.
Include AtMost in verification_has_lower_bound_of_zero() so explicit
zero-match verification with atmost=n marks matching stubs as
intentionally checked.

This aligns bookkeeping with existing verification semantics where
atmost already allows zero matches, and fixes follow-up
verifyStubbedInvocationsAreUsed/InOrder zero-lower-bound flows.
Add focused tests showing that typing.Protocol works as a spec for
method existence checks, async/sync method behavior, and signature
validation, including inherited override signatures.
Create internal chain mocks in strict mode so unexpected/unconfigured
chain segments fail early with InvocationError instead of returning
None and crashing later with AttributeError.

Add regression coverage in chaining_test.py that asserts the exact
error message for mismatched chain segment arguments.
Partially reverts 8f13528 ("Fix dummy
single-stub rollback with registry unstub_mock")

In the test for the patch, we can clearly see that `dog` is still in
the scope of the function, so we cannot unregister it which would break
its tie its theMock.

In fact expecting `ArgumentError` is wrong for the non-strict mock. For
`verify` we raise a `VerificationError`, and ensure that by testing
before and after the failing configuration try.
@kaste kaste force-pushed the dev branch 2 times, most recently from e8b67cb to 4446697 Compare March 4, 2026 09:02
@kaste kaste merged commit cd7ccc4 into master Mar 4, 2026
50 checks passed
@kaste kaste deleted the dev branch March 4, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant